<template>
  <template
    v-for="(item, index) in props.menuData"
    :key="`${props.index}-${item.meta.id}`"
  >
    <el-menu-item
      v-if="!item.children || item.children.length == 0"
      :index="`${props.index}-${item.meta.id}`"
      @click="HrefTz(item)"
    >
      <el-icon>
        <component :is="item.meta.icon"></component>
      </el-icon>
      <span>{{ item.meta.name }}</span>
    </el-menu-item>

    <el-sub-menu v-else :index="`${props.index}-${item.meta.id}`">
      <template #title>
        <el-icon>
          <component :is="item.meta.icon"></component>
        </el-icon>
        <span>{{ item.meta.name }}</span>
      </template>
      <TreeMune
        :index="`${props.index}-${item.meta.id}`"
        :menuData="item.children"
      />
    </el-sub-menu>
  </template>
</template>

<script setup>
import { useRouter } from "vue-router";
import { useMenuStore } from "../store/index";
// imports and composables
const props = defineProps(["menuData", "index"]);

const MenuStore = useMenuStore();
const router = useRouter();
function HrefTz(item) {
  MenuStore.SelectMenu(item.meta);
  router.push({ path: item.meta.path });
}
</script>

<style scoped lang="less">
/* styles */
</style>